var dataList = JSON.parse(sessionStorage.getItem("mapList"));
// //console.log("dataList is ssss ", dataList)
var nameMap = new Map()
var maxCount = 0;
//以下参考：
//https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
function reqListener() {
    var geoResponse = JSON.parse(this.responseText).features
    const nameWithId = new Map();
    for (var index in dataList) {//看看什么city是想要寻找adcode的
        nameWithId.set(dataList[index].chineseProvinceName, null)
    }
    var count = 0;
    for (var index in geoResponse) {//给每一个需要adcode的city寻找相应的adcode
        var cityName = geoResponse[index].properties.name//这里还可以继续完善

        for (let i = cityName.length - 1; i >= 1; i--) {
            if (nameWithId.has(cityName)) break
            cityName = cityName.substring(0, i);
        }
        if (nameWithId.has(cityName)) {
            count++;
            var adcode = geoResponse[index].properties.adcode
            nameWithId.set(cityName, adcode)
        }
        if (count == dataList.length) break
    }

    var tmpMapList = []
    //给dataList赋值
    for (var index in dataList) {
        var n = parseInt(dataList[index].countNumber)
        var chineseProvinceName = dataList[index].chineseProvinceName
        englishProvinceName = dataList[index].englishProvinceName
        tmpMapList.push({ 'id': nameWithId.get(chineseProvinceName), 'name': chineseProvinceName, 'value': n })
        if (maxCount < n) maxCount = n
        nameMap.set(englishProvinceName, chineseProvinceName)
    }
    dataList = tmpMapList
}


//https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest/response
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);

oReq.open("GET", "https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json", false);//重点：设置为false
oReq.send();




var myChart = echarts.init(document.getElementById('china_map'));
// //console.log("maxCount is",maxCount)
option = {
    tooltip: {
        formatter: function (params) {
            var nameArr = params.seriesName.split(",");
            var num1 = 0;
            if (!isNaN(params.value)) {
                num1 = params.value;
            }
            return params.name + '<br />' + nameArr[0] + '：' + num1;
        }//数据格式化
    },
    visualMap: {
        min: 0,
        max: maxCount,
        left: 'left',
        top: 'bottom',
        text: ['高', '低'],//取值范围的文字
        inRange: {
            color: ['#0505a2', '#0505fd']//取值范围的颜色 /https://blog.csdn.net/weixin_48337566/article/details/123941364/
            //=>https://www.w3schools.cn/colors/colors_hexadecimal.html 这个来查看时间也是非常不错的。
        },
        show: true//图注
    },
    geo: {
        map: 'china',
        roam: false,//不开启缩放和平移
        zoom: 1.23,//视角缩放比例
        label: {
            normal: {
                show: true,
                fontSize: '10',
                color: 'rgba(0,0,0,0.7)'
            }
        },
        itemStyle: {
            normal: {
                borderColor: 'rgba(0, 0, 0, 0.2)'
            },
            emphasis: {
                areaColor: '#F3B329',//鼠标选择区域颜色
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowBlur: 20,
                borderWidth: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
        },
        // nameMap : this.nameMap  
    },

    series: [
        {
            name: '数量',//设置鼠标显示的信息，可选
            type: 'map',
            geoIndex: 0,
            data: dataList,
        }
    ]
};

// //console.log("option is ", option)